<template>
  <!-- 轮播图 -->
  <!-- Swiper -->
  <div class="swiper-container" :id="'swiper' + time">
    <div class="swiper-wrapper">
      <slot></slot>
    </div>
  </div>
</template>
<script>
import Swiper from 'swiper';
export default {
  data() {
    return {
      time: new Date().getTime(),
    };
  },
  props: {
    swiperOption: {
      type: Object,
      default: () => {},
    },
  },
  mounted() {
    this.myswiper();
  },
  methods: {
    myswiper() {
      const _this = this;
      new Swiper(
        '#swiper' + this.time,
        Object.assign(
          {
            loop: true,
            autoplay: true,
            on: {
              slideChangeTransitionStart: function () {
                // console.log(this);
                // console.log(_this);
                // alert(this.activeIndex); //切换结束时，告诉我现在是第几个slide
                _this.$emit('change', this.activeIndex);
              },
            },
          },
          this.swiperOption
        )
      );
    },
  },
};
</script>
<style lang="scss">
@import '../../../node_modules/swiper/src/swiper.scss';
.swiper-container {
  width: 100%;
  height: 100%;
  // height: 9.375rem;
  overflow: hidden;
}

.swiper-slide {
  text-align: left;
  font-size: 18px;
  background: transparent;
  cursor: pointer;

  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: space-around;
  justify-content: space-around;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}
</style>
